#!/usr/env/bin python
# -*- coding: utf-8 -*-

# @Time    : 2020/2/12 10:10|10:10
# @Author  : yangdingyi
# @File    : 四数相加 II
# @Software: PyCharm
from typing import List


class Solution:
    def fourSumCount(self, A: List[int], B: List[int], C: List[int], D: List[int]) -> int:
        m = {}
        ans = 0
        for i in range(len(A)):
            for j in range(len(B)):
                n = -A[i] - B[j]
                # if m.get(n):
                if n in m:
                    m[n] += 1
                else:
                    m[n] = 1
        for i in range(len(C)):
            for j in range(len(D)):
                n = C[i] + D[j]
                # if m.get(n):
                if n in m:
                    ans += m[n]
        return ans


solve = Solution()

A = [1, 2]
B = [-2, -1]
C = [-1, 2]
D = [0, 2]

print(A)
print(B)
print(C)
print(D)

print(solve.fourSumCount(A, B, C, D))





